home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch9 / Arctan2.bas next >
Encoding:
BASIC Source File  |  1999-05-29  |  487 b   |  22 lines

  1. Attribute VB_Name = "Arctan"
  2. Option Explicit
  3.  
  4. ' Return the arc tangent of y/x taking into
  5. ' account the proper quadrant.
  6. Public Function Arctan2(x As Single, y As Single)
  7. Const PI = 3.14159265
  8. Dim theta As Single
  9.  
  10.     If x = 0 Then
  11.         If y > 0 Then
  12.             Arctan2 = PI / 2
  13.         Else
  14.             Arctan2 = -PI / 2
  15.         End If
  16.     Else
  17.         theta = Atn(y / x)
  18.         If x < 0 Then theta = PI + theta
  19.         Arctan2 = theta
  20.     End If
  21. End Function
  22.